<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        
        ul {
            list-style-type: none;
        }
        
        .list li {
            width: 100px;
            height: 100px;
            border: 1px solid red;
            float: left;
        }
    </style>
</head>

<body>
    <ul class="list">
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
    </ul>
    <script>
        // 获取索引位
        // 获取是伪数组
        // js单线程
        var lis = document.getElementsByTagName('li');
        for (var i = 0; i < lis.length; i++) {
            (function(t) {
                lis[t].onclick = function() {
                    console.log(t);
                };
            })(i)
        };
    </script>
</body>

</html>